﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Lib.Utils;

namespace MS.INV
{
    public partial class CustomerUs : Control
    {
        DataTable DT = new DataTable();

        public bool IsCustomer { get; set; }

        public int IdKhachHang 
        {
            get { return Cvert.ToInt32(cboKH.EditValue, 0); }
            set { cboKH.EditValue = value; }
        }

        public CustomerUs()
        {
            InitializeComponent();

            cboKH.EditValueChanged += new EventHandler(cboKH_EditValueChanged);
        }

        void cboKH_EditValueChanged(object sender, EventArgs e)
        {
            if (DT == null || DT.Rows.Count <= 0) return;

            DataRow[] rS = DT.Select("IdKhachHang=" + Cvert.ToInt32(cboKH.EditValue, 0));
            if (!Is.IsNullOrEmpty(rS))
            {
                txtMa.Text = Cvert.ToString(rS[0]["MaKhachHang"], "");
                txtDC.Text = Cvert.ToString(rS[0]["DiaChi"], "");
                txtMST.Text = Cvert.ToString(rS[0]["MST"], "");
                txtDT.Text = Cvert.ToString(rS[0]["DienThoai1"], "") + " - " + Cvert.ToString(rS[0]["DienThoai2"], "");
            }
        }

        public void LoadData()
        {
            using (SysObj.L_KhachHang kh = new SysObj.L_KhachHang())
            {
                DT = kh.LoadData();
            }

            cboKH.SetDataSource(DT);

            if (IsCustomer)
                labelControl1.Text = "Khách hàng";
        }
    }
}
